#!/bin/sh
set -e

# 从环境变量读取配置，提供默认值
REDIS_ADDR="${REDIS_ADDR:-127.0.0.1:6379}"
REDIS_PASSWORD="${REDIS_PASSWORD:-}"
REDIS_KEY="${REDIS_KEY:-}"
LISTEN_ADDR="${LISTEN_ADDR:-:9100}"

if [ -z "$REDIS_KEY" ]; then
  echo "Error: environment variable REDIS_KEY is not set."
  exit 1
fi

ARGS="-redis.addr $REDIS_ADDR -redis.password $REDIS_PASSWORD -redis.key $REDIS_KEY -web.listen-address $LISTEN_ADDR"

echo "Starting redis_key_exporter with args: $ARGS"

exec /app/redis_key_exporter $ARGS
